package com.shangke.corejava.ch14;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class ChatServer3 {
	public void start(){
		int port =8888;
		ServerSocket serverSocket=null;
		
		try {
			serverSocket=new ServerSocket(port);
			System.out.println("服务器启动成功");
			
			while(true){
				Socket socket=serverSocket.accept();
				System.out.println(""+socket.getInetAddress().getHostAddress()+""+socket.getPort());
				new Thread(new Chat(socket)).start();
			}
			
		} catch (IOException e) {
			e.printStackTrace();
		} finally{
			if (serverSocket != null) {
				try {
					serverSocket.close();
				} catch (IOException e) {
				}
			}
		}
	}
	public static void main(String[] args) {
		ChatServer3 chatServer3=new ChatServer3();
		chatServer3.start();

	}

}
